# -*- perl -*-

# t/001_load.t - check module loading and create testing directory

use lib 'lib';
use Test::More tests => 15;

BEGIN {
    use_ok('OOXML::Utils::Wordprocessing');
    use_ok('OOXML::Utils::Spreadsheet');
    use_ok('OOXML::Utils::Presentation');
}

# Check we can create objects
my $docx = OOXML::Utils::Wordprocessing->new();
isa_ok($docx, 'OOXML::Utils::Wordprocessing');

my $xlsx = OOXML::Utils::Spreadsheet->new();
isa_ok($xlsx, 'OOXML::Utils::Spreadsheet');

my $pptx = OOXML::Utils::Presentation->new();
isa_ok($pptx, 'OOXML::Utils::Presentation');

# Check we can read files into objects
is($docx->init_from_file('t/samples/sample.docx'), 1,
   'Can we read sample wordprocessing document?');
is($xlsx->init_from_file('t/samples/sample.xlsx'), 1,
   'Can we read sample spreadsheet document?');
is($pptx->init_from_file('t/samples/sample.pptx'), 1,
   'Can we read sample presentation document?');

# Check we can find the main part of each document
my $docx_main_part = $docx->get_package()->get_main_part();
is($docx_main_part, 'word/document.xml',
   'Can we find the main part of a wordprocessing document?');

my $xlsx_main_part = $xlsx->get_package()->get_main_part();
is($xlsx_main_part, 'xl/workbook.xml',
   'Can we find the main part of a spreadsheet document?');

my $pptx_main_part = $pptx->get_package()->get_main_part();
is($pptx_main_part, 'ppt/presentation.xml',
   'Can we find the main part of a presentation document?');

# Check the content type for each part
my $base_ct = 'application/vnd.openxmlformats-officedocument';
is($docx->get_package()->get_content_type_for_part($docx_main_part),
   "$base_ct.wordprocessingml.document.main+xml",
   'Can we find the content type for the main part?');

is($xlsx->get_package()->get_content_type_for_part($xlsx_main_part),
   "$base_ct.spreadsheetml.sheet.main+xml",
   'Can we find the content type for the main part?');

is($pptx->get_package()->get_content_type_for_part($pptx_main_part),
   "$base_ct.presentationml.presentation.main+xml",
   'Can we find the content type for the main part?');
